
package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.BalanceBean;
import com.ukao.steward.bean.OrderInfoBean;
import com.ukao.steward.bean.StringBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.util.CheckUtils;
import com.ukao.steward.util.L;
import com.ukao.steward.util.T;
import com.ukao.steward.view.valetRunners.OrderInfoView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class OrderInfoPesenter extends BasePresenter<OrderInfoView> {


    public OrderInfoPesenter(OrderInfoView view) {
        attachView(view);
    }





    public void payInfo(String  id ) {
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("id",id);
        mHashMap.put("accessToken", SaveParams.getToken());
        L.i("mHashMap="+mHashMap.toString());

        addSubscription( apiStores.payInfo(Constant.createParameter(mHashMap)),
                new ApiCallback<OrderInfoBean>() {
                    @Override
                    public void onSuccess(OrderInfoBean model) {

                        if (model.getHttpCode() == 200) {
                           mvpView.OrderInfoSucceed(model.getData());


                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }


    /*用户余额*/
    public void userExtbalance(int userId    ) {

        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("id", String.valueOf(userId));
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.userExtbalance(Constant.createParameter(mHashMap)),
                new ApiCallback<BalanceBean>() {
                    @Override
                    public void onSuccess(BalanceBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.useBalanceData(model.getData());

                        } else {

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                    }

                });
    }

    /**
     *   余额支付
     * @param orderId  订单ID
     * @param balance   使用余额
     * @param isUseUPay  是否使用优付卡
     * @param cpnRelId   优惠卷  id
     */
    public void confirmPay(String  orderId,int  balance,boolean isUseUPay,String  cpnRelId ) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderId", orderId);
        if(isUseUPay){
            mHashMap.put("groupCardType","41");//groupCardType 支付(团)卡类型 41-优付卡
        }else{
            mHashMap.put("balance", String.valueOf(balance));
        }
        if (!CheckUtils.isEmpty(cpnRelId)){
            mHashMap.put("cpnRelId", cpnRelId);
        }
        mHashMap.put("accessToken", SaveParams.getToken());
        L.i("mHashMa="+mHashMap.toString());
        addSubscription(apiStores.confirmPay(Constant.createParameter(mHashMap)),
                new ApiCallback<BalanceBean>() {
                    @Override
                    public void onSuccess(BalanceBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.hideLoading();
                            mvpView.confirmPaySucceed();
                        } else {
                            T.show(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /*支付解锁*/
    public void unlockOrder(String orderId    ) {
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("orderId", orderId);
        mHashMap.put("accessToken", SaveParams.getToken());
        addSubscription(apiStores.unlockOrder(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.unlockOrderData(  );

                        } else {

                            T.show(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                    }

                });
    }


}
